﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using HR_Implement;
namespace Hr_HostApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        TcpChannel channel = null;

        private void btn_start_Click(object sender, EventArgs e)
        {
            try
            {
                HR_Implement.EmployeeRemotingObject imp = new EmployeeRemotingObject();

               BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                //SoapServerFormatterSinkProvider serverProvider = new SoapServerFormatterSinkProvider();
 
                serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                System.Collections.IDictionary props = new System.Collections.Hashtable();
                props["port"] = int.Parse(txt_port.Text);
                channel = new TcpChannel(props,null,serverProvider);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(EmployeeRemotingObject), "EmployeeRemotingObject", WellKnownObjectMode.SingleCall);
                ChannelServices.RegisterChannel(channel);
            }
            catch (Exception ex)
            {
                toolStripLabel1.Text = ex.Message;

            }
            toolStripLabel1.Text = "Open";

        }

        private void btn_stop_Click(object sender, EventArgs e)
        {
            ChannelServices.UnregisterChannel(channel);
            toolStripLabel1.Text = "Stop";
        }

    }
}
